package com.cyufeng.blog.common;

import java.text.*;
import java.util.Calendar;
//
//public class SetCode {
//}


public class SetCode {


    /** The FieldPosition. */
    private static final FieldPosition HELPER_POSITION = new FieldPosition(0);

    /** 时间格式*/
    private final static Format dateFormat = new SimpleDateFormat("MMddHHmmssS");

    /** NumberFormat表示数字的格式化类 */
    private final static NumberFormat numberFormat = new DecimalFormat("0000");

    /** 这个int是序列号，默认值是 0. */
    private static int seq = 0;

    private static final int MAX = 9999;

    /**
     * 生成唯一标示
     * @return String
     */
    public static  String setcode() {

        Calendar rightNow = Calendar.getInstance();

        StringBuffer sb = new StringBuffer();

        dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION);

        numberFormat.format(seq, sb, HELPER_POSITION);

        if (seq == MAX) {
            seq = 0;
        } else {
            seq++;
        }
        return sb.toString();
    }
}